package com.quanshu.exchange.ui.gui.message;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.quanshu.exchange.R;
import com.quanshu.exchange.support.utils.RxViewHelper;
import com.quanshu.exchange.ui.base.BaseDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.subjects.BehaviorSubject;

/**
 * Created by xiniu003 on 2017/12/7.
 */

public class DialogMessageMenu extends BaseDialog {

    @BindView(R.id.llt_group_send_message)
    RelativeLayout lltGroupSendMessage;
    @BindView(R.id.llt_add_friend)
    RelativeLayout lltAddFriend;
    @BindView(R.id.llt_add_group)
    RelativeLayout lltAddGroup;
    @BindView(R.id.llt_create_group)
    RelativeLayout lltCreateGroup;
    @BindView(R.id.rlt_top)
    RelativeLayout rltTop;
    @BindView(R.id.llt_scan_qr)
    RelativeLayout lltScanQr;

    private BehaviorSubject behaviorSubject = BehaviorSubject.create();


    public BehaviorSubject getBehaviorSubject() {
        return behaviorSubject;
    }

    private BehaviorSubject oneBehaviorSubject = BehaviorSubject.create();

    public BehaviorSubject getOneBehaviorSubject() {
        return oneBehaviorSubject;
    }

    private BehaviorSubject twoBehaviorSubject = BehaviorSubject.create();

    public BehaviorSubject getTwoBehaviorSubject() {
        return twoBehaviorSubject;
    }

    private BehaviorSubject threeBehaviorSubject = BehaviorSubject.create();

    public BehaviorSubject getThreeBehaviorSubject() {
        return threeBehaviorSubject;
    }

    private BehaviorSubject fourBehaviorSubject = BehaviorSubject.create();

    public BehaviorSubject getFourBehaviorSubject() {
        return fourBehaviorSubject;
    }

    private BehaviorSubject scanBehaviorSubject = BehaviorSubject.create();

    public BehaviorSubject getScanBehaviorSubject() {
        return scanBehaviorSubject;
    }

    public DialogMessageMenu(@NonNull Context context) {
        super(context);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_message_menu);
        ButterKnife.bind(this);
        initView();
    }

    @Override
    public void init(@NonNull Context context) {
        Window window = getWindow();
        window.setWindowAnimations(R.style.TopAnim);
        window.setGravity(Gravity.TOP);
        //默认的Dialog只有5/6左右的宽度，改为全屏宽度,由dialog的布局自己来决定实际显示宽度
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    @Override
    public boolean isCancelAble() {
        return true;
    }

    private void initView() {

        RxViewHelper.getInstance().clicks(rltTop, aVoid -> behaviorSubject.onNext(rltTop));

        RxViewHelper.getInstance().clicks(lltGroupSendMessage, aVoid -> oneBehaviorSubject.onNext(lltGroupSendMessage));

        RxViewHelper.getInstance().clicks(lltAddFriend, aVoid -> twoBehaviorSubject.onNext(lltAddFriend));

        RxViewHelper.getInstance().clicks(lltAddGroup, aVoid -> threeBehaviorSubject.onNext(lltAddGroup));

        RxViewHelper.getInstance().clicks(lltCreateGroup, aVoid -> fourBehaviorSubject.onNext(lltCreateGroup));

        RxViewHelper.getInstance().clicks(lltScanQr, aVoid -> scanBehaviorSubject.onNext(aVoid));
    }
}
